<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
      xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3" xmlns:head="http://www.w3.org/1999/html">
<head th:include="public/public_css::public_css ('库位组管理')"/>

<body style="background-color: #f2f2f2;">
<div class="layui-fluid larry-wrapper">
    <div class="layui-card">
        <div class="layui-row layui-col-space30">
            <div class="layui-col-xs24">
                <form class="layui-form layui-card-header  layui-card-header-auto" id="searchForm">
                    <div class="layui-inline">
                        <label class="layui-form-label">库位组名称</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="mc" name="mc" placeholder="库位组名称"/>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">库位组描述</label>
                        <input type="text" class="layui-input" id="ms" name="ms" placeholder="库位组描述"/>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">激活状态</label>
                        <select name="sfyx" lay-filter="aihao">
                            <option value="">全部</option>
                            <option value="0">禁用</option>
                            <option value="1">启用</option>
                        </select>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">类型</label>
                        <select name="kwzlx" lay-filter="aihao">
                            <option value="">全部</option>
                            <option value="0">收货</option>
                            <option value="1">上架</option>
                            <option value="2">集货</option>
                            <option value="3">作业区</option>
                        </select>
                    </div>

                    <div class="layui-inline inline-search-btn">
                        <a class="layui-btn layui-btn-normal" data-type="reload">查询</a>
                    </div>
                    <div class="layui-inline inline-reset-btn">
                        <button type="reset" class="layui-btn layui-btn-primary" style="background-color: #1e9fff; color: white;">重置</button>
                    </div>
                </form>
                <!--顶部按钮展示区域 【 tpl-button 】 -->
                <div class="group-button tpl-button" id="toolbar"></div>
                <!--列表-->
                <section class="panel panel-padding layui-card-body">
                    <div class="pro">
                        <table id="table" class="table text-nowrap"></table>
                    </div>
                </section>
            </div>
        </div>
    </div>
</div>

</body>
<div th:include="public/public_js::public_js"></div>
<div th:include="public/public_btn::public_btn"></div>
<style type="text/css">
    .moreBtn {
        width: 50px;
        height: 20px;
        text-align: center;
        color: #fff;
        line-height: 20px;
        background-color: #eee;
        position: relative;
        margin: 0 auto;
        cursor: pointer;
    }

    .moreBtn:before {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(30deg);
        background: #eee;
        border-top-left-radius: 8px;
        left: -20px;
        top: 0;
    }

    .moreBtn:after {
        content: '';
        display: block;
        width: 35px;
        height: 20px;
        position: absolute;
        transform: skewX(-30deg);
        background: #eee;
        border-top-right-radius: 8px;
        top: 0;
        right: -20px;
    }
</style>
<script th:inline="javascript">
    var functions = [[${functions}]];
    //	回车查询
    console.log(functions);
    document.onkeydown = function(event) {
        e = event ? event : (window.event ? window.event : null);
        if (e.keyCode == 13) {
            //执行的方法
            $('#search_button').click();
        }
    };
    layui.use(['list', 'layer', 'zzpUtils', 'jquery', 'laydate','tablebutton'], function () {
        var zzpUtils = layui.zzpUtils,
            $ = layui.jquery,
            laydate = layui.laydate,
            tablebtn = layui.tablebutton;
        var $table;
        tablebtn.buildOnClick({
            type: 1,
            temp: $("#function_tpl"),
            functions: functions.headBtn,
            row: null,
            event: {
                searchEvent: function(){
                    zzpUtils.refreshTable("#table");
                },
                //新增
                addEvent: function (data) {
                    add();
                },
                /*编辑*/
                editEvent: function (data) {
                    if (data.row != undefined) {
                        upDialog(data);
                    }
                },
                //启用
                enableEvent: function (data) {
                    if (data.row != undefined) {
                        startDialog(data.row.id);
                    } else {
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length == 1) {
                            startDialog($rows[0].id);
                        }
                    }
                },

                //禁用
                disableEvent: function (data){
                    console.log(data);
                    if (data.row != undefined) {
                        stopDialog(data.row.id);
                    } else {
                        var $rows = $table.bootstrapTable('getSelections');
                        if ($rows.length == 1) {
                            stopDialog($rows[0].id);
                        }
                    }
                },


                //查看
                getEvent: function (data) {
                    if (data.row != undefined) {
                        getDialog(data);
                    }
                },

            }


        });
        //初始化
        zzpUtils.webSocket.init();
        //新增
        function add() {
            zzpUtils.dialog({
                title: "新增库位组",
                type: 2,
                content: "/groupRouter/toAddgroup",
                area: ['80%', '90%'], //设置dialog大小，也可以不设置，
                end: function () {//增加成功后刷新
                    zzpUtils.refreshTable("#table");
                }
            });
        }
        //编辑库位
        function upDialog(data) {
            var id=data.row.id;
            var sfyx=data.row.sfyx;
            if (sfyx == 0) {
                layer.msg("该库位组已禁用，不可编辑！");
            } else {
                zzpUtils.dialog({
                    title: "修改库位组",
                    type: 2,
                    content: "/groupRouter/toEditgroup?id=" + id,
                    area: ['55%', '55%'], //设置dialog大小，也可以不设置，
                    end: function () {//修改成功后刷新
                        zzpUtils.refreshTable("#table");
                    }
                });
            }
        }
//禁用库位组
        function stopDialog(id) {
            var ids = [];
            ids.push(id);
            zzpUtils.confirm("是否确定禁用库位组",function (index) {
                zzpUtils.action({
                    url: "/wmslibrarypositiongroup/bjh" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        setTimeout(function () {
                            layer.msg(data.title);
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;

        }
        //启用库位组
        function startDialog(id) {
                 var ids = [];
            ids.push(id);
            zzpUtils.confirm("是否确定启用库位组", function (index) {
                zzpUtils.action({
                    url: "/wmslibrarypositiongroup/yjh" ,
                    data: JSON.stringify({ids:ids}),
                    success: function (data) {
                        setTimeout(function () {
                            layer.msg(data.title);
                        }, 500);
                        zzpUtils.refreshTable("#table");
                    }, error: function (xhr, textStatus) {
                        console.log(textStatus);
                        console.log(xhr)
                    }
                })
            })
            return false;
        }

        //查看库位
        function getDialog(data) {
            var id=data.row.id;
            var kwzlx=data.row.kwzlx;
            zzpUtils.dialog({
                title: "查看库位",
                type: 2,
                content: "/groupRouter/toChakanKw?id=" + id+"&kwzlx="+kwzlx,
                area: ['70%', '70%'], //设置dialog大小，也可以不设置，
            });
        }

        //查询列表
        var $table = zzpUtils.table({
            elem: '#table',
            isApi: true,
            pagination: true,
            isOperate: true,
            functions: functions.tableBtn,
            url: '/wmslibrarypositiongroup/list',
            columns: [
             {
                field: 'mc',
                title: '库位组名称'
            }, {
                field: 'ms',
                title: '库位组描述'
            },  {
                field: 'show_kwzlx',
                title: '库位组类型'
            },{
                field: 'kws',
                title: '库位数'
            }, {
                field: 'show_sfyx',
                title: '激活状态'
            }],
            queryParams: function () {//查询条件
                return  zzpUtils.getFormJson($("#searchForm"));
            },
            detailFormatter: function (index, row) {
                return "这里就没有确定过11";
            },
            /*定义表格右侧按钮*/
            operateFormatter: operateFormatter
        });
        $(".inline-search-btn").on('click',function () {
            zzpUtils.refreshTable("#table");
        })

        /*表格右侧按钮*/
        function operateFormatter(value, row, index) {
            var btn = '', button = '', buttons1 = '', buttons2 = '';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var item = functions.tableBtn[i];
                var Disable = '<button class="layui-btn layui-btn-xs layui-btn-disabled" disabled lay-event="' + item.event + '">' + item.name + '</button>';
                var Enable = '<button class="layui-btn layui-btn-xs layui-btn-normal" lay-event="' + item.event + '">' + item.name + '</button>';
                switch (item.event) {
                    case 'disableEvent'://禁用按钮
                        if(row.sfyx == '1')
                            buttons1 += Enable;//显示
                        else
                            buttons1 += Disable;//灰色禁用
                        break;
                    case 'editEvent'://编辑按钮
                        if(row.sfyx == '1')
                            buttons1 += Enable;//显示
                        else
                            buttons1 += Disable;//灰色禁用
                        break;
                    case 'getEvent':// 查看库位按钮
                        if(row.sfyx == '1')
                            buttons1 += Enable;
                        else
                            buttons1 += Disable;
                        break;

                    case 'enableEvent'://启用按钮
                        if(row.sfyx == '0')
                            buttons1 += Enable;//显示
                        else
                            buttons1 += Disable;//灰色禁用
                        break;
                    default:
                        buttons1 += Enable;
                }

            }
            button += buttons1;
            button += buttons2;
            button += '</span></div>';
            return button;
        }
        /*表格右侧按钮原来带三个点的操作按钮*/
       /* function operateFormatter(value, row, index) {
            var button = '<a class="tooltip2" id="tooltip' + row.id + '" data-tooltip-content="#tool' + row.id + '" id="btn_start"><i class="layui-icon layui-icon-more"></i></a>'
                + '<div class="tooltip_templates">'
                + '<span id="tool' + row.id + '">';
            for (var i = 0; i < functions.tableBtn.length; i++) {
                var btn = '<a class="layui-btn layui-btn-sm layui-btn-warm" lay-event="' + functions.tableBtn[i].event + '">'
                    + functions.tableBtn[i].name
                    + '</a>';
                if (row.sfyx == '1') {
                    if (functions.tableBtn[i].name == '禁用' || functions.tableBtn[i].name == '编辑' || functions.tableBtn[i].name == '查看') {
                        button += btn;
                    }
                } else if (row.sfyx == '0') {
                    if (functions.tableBtn[i].name == '启用' ) {
                        button += btn;
                    }
                }
            }
            button += '</span>'
                + '</div>';
            return button;
        }*/

        /*双击查看详情*/
        function btn_cha(id){
            var zzpUtils = layui.zzpUtils,
                $ = layui.jquery,
                laydate = layui.laydate;
            zzpUtils.dialog({
                title: "库位组详情",
                type: 2,
                content: "/groupRouter/getFindKwz?id=" + id,
                area: ['65%', '65%'], //设置dialog大小，也可以不设置，
            });

        }
    });


</script>
</html>